package ZhuangXiang;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;
import org.w3c.dom.ls.LSOutput;

/**
 * 装箱和拆箱
 */
public class ZhuangXiang {
    public static void main(String[] args) {
        Animal animal = new Animal();
    animal.name="动物";
    animal.eat();
        Cat cat = new Cat();
        cat.name="Tom";
        cat.color="白色";
        Dog dog = new Dog();
        dog.name="jack";
        dog.sex="男";
        System.out.println("父类作为形参的");
        Animal ani = new Cat();
        Person person = new Person();
        person.name="yao";
        person.wei(cat);
        person.wei(dog);
//        System.out.println("====拆箱,将父类引用的真实子类对象,转为其本身类型");
//        Dog dog1 = (Dog)ani;
//        System.out.println(dog1.sex);
//        Cat cat1 =(Cat)ani;
//        System.out.println(cat1.color);

    }
}
class Person{
    String name;
    public void  wei(Animal ani){

        System.out.print("名为"+name+"喂吃饭");
        ani.eat();
    }
}
class Animal{
    String name;
    public void eat(){
        System.out.print(name+"在吃饭");
    }
}
class Cat extends  Animal{
    String color;
    public void eat(Cat cat){
        System.out.print(color+name+"在吃饭");
    }
}
class Dog extends  Animal{
    String sex;
    public void eat(Dog dog){
        System.out.print("性别为"+sex+name
                +"在吃饭");
    }
}